package jch.learn.java.advanced.chapter2_InputAndOutput;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.UserPrincipal;

public class TestFilesInfo {

    public static void main(String[] args) throws IOException {
        Path filePath = Paths.get(TestFilesInfo.class.getResource("/chapter2/employee.dat").getPath().substring(1));
        System.out.println("获取文件大小：" + Files.size(filePath));
        System.out.println("获取文件的拥有者信息：");
        UserPrincipal userPrincipal = Files.getOwner(filePath);
        System.out.println("拥有者信息：" + userPrincipal);
        System.out.println("读取文件基础属性信息：" + Files.readAttributes(filePath, BasicFileAttributes.class).toString());
        PosixFileAttributes posixFileAttributes = Files.readAttributes(filePath, PosixFileAttributes.class);
        System.out.println("读取文件兼容属性信息：" + posixFileAttributes.owner());
    }
}
